package com.itg.vms.servlet;

import com.itg.vms.entity.User;
import com.itg.vms.entity.vo.Log;
import com.itg.vms.service.LogService;
import com.itg.vms.service.impl.LogServiceImpl;
import com.itg.vms.util.StringUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author zjzaki
 * @create 2023年03月11日 10:33:10
 */
@WebServlet("/api/log")
public class LogServlet extends BaseServlet{

    LogService logService = new LogServiceImpl();

    /**
     * 分页查询所有的日志信息
     */
    public void getAllLog(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //得到请求参数
        String page = req.getParameter("page");
        Integer currentPage = Integer.valueOf(page);
        String limit = req.getParameter("limit");
        Integer pageSize = Integer.valueOf(limit);

        //当前页面数减1，mysql分页从第0也开始
        currentPage = currentPage - 1;
        //调用业务层方法查询数据
        List<Log> logs = logService.selectAllLog(currentPage,pageSize);
        //得到user表的总记录数
        Long allLogSize = logService.getAllLogSize();
        //判断这个列表是否为null，为null查询失败
        if (StringUtils.isNotNull(logs)) {
            resp.getWriter().write(success(logs, allLogSize));
        } else {
            resp.getWriter().write(error("查询失败"));
        }
    }
}
